package com.hwadee.teachingprocessmanagementsystem.service.base.impl;

import com.hwadee.teachingprocessmanagementsystem.entity.Attendance;
import com.hwadee.teachingprocessmanagementsystem.dao.AttendanceDao;
import com.hwadee.teachingprocessmanagementsystem.service.base.AttendanceService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

/**
 * 教师考勤表(Attendance)表服务实现类
 *
 * @author makejava
 * @since 2024-07-11 14:20:02
 */
@Service("attendanceService")
public class AttendanceServiceImpl implements AttendanceService {
    @Resource
    private AttendanceDao attendanceDao;

    /**
     * 通过ID查询单条数据
     *
     * @param attendanceId 主键
     * @return 实例对象
     */
    @Override
    public Attendance queryById(Integer attendanceId) {
        return this.attendanceDao.queryById(attendanceId);
    }

    /**
     * 分页查询
     *
     * @param attendance 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Attendance> queryByPage(Attendance attendance, PageRequest pageRequest) {
        long total = this.attendanceDao.count(attendance);
        return new PageImpl<>(this.attendanceDao.queryAllByLimit(attendance, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param attendance 实例对象
     * @return 实例对象
     */
    @Override
    public Attendance insert(Attendance attendance) {
        this.attendanceDao.insert(attendance);
        return attendance;
    }

    /**
     * 修改数据
     *
     * @param attendance 实例对象
     * @return 实例对象
     */
    @Override
    public Attendance update(Attendance attendance) {
        this.attendanceDao.update(attendance);
        return this.queryById(attendance.getAttendanceId());
    }

    /**
     * 通过主键删除数据
     *
     * @param attendanceId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer attendanceId) {
        return this.attendanceDao.deleteById(attendanceId) > 0;
    }
}
